package com.itr.kbm.dao.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.itr.kbm.dao.FileStatusDao;
import com.itr.kbm.model.FileStatus;

@Repository
public class FileStatusDaoImpl extends AbstractDaoImpl<FileStatus, Integer>
		implements FileStatusDao {

	protected FileStatusDaoImpl() {
		super(FileStatus.class);
	}

	// KOPEG
	public List<FileStatus> findByDate(String month, String year) {

		String type = "uploadKopeg";
		Criteria criteria = getCurrentSession()
				.createCriteria(FileStatus.class);
		criteria.add(Restrictions.eq("type", type));
		criteria.add(Restrictions.eq("month", month));
		criteria.add(Restrictions.eq("year", year));

		return criteria.list();
	}

	public List<FileStatus> findCompare(String month, String year) {

		String[] type = new String[4];
		type[0] = "uploadCompareAngsuranLainLain";
		type[1] = "uploadCompareAngsuranTetap";
		type[2] = "uploadCompareSimpananTetap";
		type[3] = "uploadCompare";

		Criteria criteria = getCurrentSession()
				.createCriteria(FileStatus.class);
		criteria.add(Restrictions.in("type", type));
		criteria.add(Restrictions.eq("month", month));
		criteria.add(Restrictions.eq("year", year));

		return criteria.list();
	}

	public List<FileStatus> findFinalReport(String month, String year) {

		String[] type = new String[4];
		type[0] = "uploadFinalReportAngsuranLainLain";
		type[1] = "uploadFinalReportAngsuranTetap";
		type[2] = "uploadFinalReportSimpananTetap";
		type[3] = "uploadFinalReport";

		Criteria criteria = getCurrentSession()
				.createCriteria(FileStatus.class);
		criteria.add(Restrictions.in("type", type));
		criteria.add(Restrictions.eq("month", month));
		criteria.add(Restrictions.eq("year", year));

		return criteria.list();
	}
	
	
	// KOPTEL PRODUCT
	public List<FileStatus> findByDateProduct(String month, String year) {

		String[] type = new String[3];
		type[0] = "uploadAngsuranLainLain";
		type[1] = "uploadAngsuranTetap";
		type[2] = "uploadAngsuran";
		
		Criteria criteria = getCurrentSession()
				.createCriteria(FileStatus.class);
		criteria.add(Restrictions.in("type", type));
		criteria.add(Restrictions.eq("month", month));
		criteria.add(Restrictions.eq("year", year));

		return criteria.list();
	}

	public List<FileStatus> findCompareProduct(String month, String year) {

		String[] type = new String[3];
		type[0] = "uploadCompareAngsuranLainLainProduct";
		type[1] = "uploadCompareAngsuranTetapProduct";
		type[2] = "uploadCompareAngsuranProduct";

		Criteria criteria = getCurrentSession()
				.createCriteria(FileStatus.class);
		criteria.add(Restrictions.in("type", type));
		criteria.add(Restrictions.eq("month", month));
		criteria.add(Restrictions.eq("year", year));

		return criteria.list();
	}

	public List<FileStatus> findFinalReportProduct(String month, String year) {

		String[] type = new String[3];
		type[0] = "uploadFinalReportAngsuranLainLainProduct";
		type[1] = "uploadFinalReportAngsuranTetapProduct";
		type[2] = "uploadFinalReportAngsuranProduct";

		Criteria criteria = getCurrentSession()
				.createCriteria(FileStatus.class);
		criteria.add(Restrictions.in("type", type));
		criteria.add(Restrictions.eq("month", month));
		criteria.add(Restrictions.eq("year", year));

		return criteria.list();
	}
}
